#include<stdio.h>
#include<stdbool.h>
typedef struct circlequeue
{
	int* arr;
	int head;
	int tail;
	int k;
}mycirclequeue, * pmycirclequeue;
pmycirclequeue mycirclequeuecreate(int k)
{
	pmycirclequeue obj = (pmycirclequeue)malloc(sizeof(mycirclequeue));
	obj->arr = malloc(sizeof(int) * (k + 1));
	obj->head = 0;
	obj->tail = 0;
	obj->k = k;
}
bool mycirclequeueisempty(pmycirclequeue obj)
{
	return obj->head == obj->tail;
}
bool mycirclequeueisfull(pmycirclequeue obj)
{
	return (obj->tail + 1) % (obj->k + 1) == obj->head;
}
bool mycirclequeueenqueue(pmycirclequeue obj, int val)
{
	if (mycirclequeueisfull(obj))
		return false;
	obj->arr[obj->tail] = val;
	obj->tail++;
	obj->tail %= (obj->k + 1);
}
int mycirclequeuerear(pmycirclequeue obj)
{
	if (mycirclequeueisempty(obj))
		return -1;
	else
		return obj->arr[(obj->tail - 1 + obj->k + 1) % (obj->k + 1)];
}
bool mycirclequeuedequeue(pmycirclequeue obj)
{
	if (mycirclequeueisempty(obj))
		return false;
		obj->head++;
	obj->head %= (obj->k + 1);
	return true;
}
int mycirclequeuefront(pmycirclequeue obj)
{
	if (mycirclequeueisempty(obj))
		return -1;
	else
		return obj->arr[obj->head];
}
void mycirclequeuefree(pmycirclequeue obj)
{
	free(obj->arr);
	free(obj);
}